package huashu.net.complain.dao;

import com.sirdc.modules.core.dao.StringDao;
import huashu.net.complain.databean.LitigationTypeDTO;
import huashu.net.complain.entity.LitigationType;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LitigationTypeDao extends StringDao<LitigationType> {

    //
    public List<LitigationTypeDTO> getTypeAmount(){
        StringBuffer sql  = new StringBuffer();
        sql.append("SELECT type name, sum(amount) sum ");
        sql.append("from t_litigationtype ");
        sql.append("GROUP BY type ");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(LitigationTypeDTO.class));
        List<LitigationTypeDTO> dtos  = (List<LitigationTypeDTO>) query.list();
        return dtos;
    }

    public List<LitigationType> getYearType(String type)
    {
        StringBuffer sql = new StringBuffer();
        sql.append(" select datetime,type,days");
        sql.append(" from t_litigationtype");
        sql.append(" where 1=1");
        if(type!=null&&!"".equals(type))
        sql.append(" and type ='"+type+"'");
        sql.append(" GROUP BY datetime,type");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(LitigationType.class));
        List<LitigationType> dtos = (List<LitigationType>) query.list();
        return dtos;
    }

}
